<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>PHP Class Manager (Smart PHP): Исходный файл pcm/users/um.class.php</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">PHP Class Manager (Smart PHP)
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">Руководство программиста по использованию PCM</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Создано системой Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Поиск');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Поиск');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_690f39e4732a141faee69ce026190629.html">pcm</a></li><li class="navelem"><a class="el" href="dir_4b9ac5fc40fe20b8599356021dd432dc.html">users</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">um.class.php</div>  </div>
</div><!--header-->
<div class="contents">
<a href="um_8class_8php.html">См. документацию.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;  declare(strict_types = 1);</div><div class="line"><a name="l00003"></a><span class="lineno"><a class="line" href="namespace_p_c_m_1_1_users.html">    3</a></span>&#160;  <span class="keyword">namespace </span><a class="code" href="namespace_p_c_m_1_1_users.html">PCM\Users</a>;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;  </div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;    require_once $_SERVER[<span class="stringliteral">&#39;DOCUMENT_ROOT&#39;</span>].<span class="stringliteral">&quot;/work_/pcm/dbc/dbc.class.php&quot;</span>;</div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;    require_once $_SERVER[<span class="stringliteral">&#39;DOCUMENT_ROOT&#39;</span>].<span class="stringliteral">&quot;/work_/pcm/users/user.class.php&quot;</span>;</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;  </div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;  use <a class="code" href="namespace_p_c_m_1_1_data_base_1_1_d_b_c.html">PCM\DataBase\DBC</a>;</div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;  </div><div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="class_p_c_m_1_1_users_1_1_user_manager.html">   26</a></span>&#160;  <span class="keyword">class </span><a class="code" href="class_p_c_m_1_1_users_1_1_user_manager.html">UserManager</a> <span class="keyword">extends</span> <a class="code" href="class_p_c_m_1_1_data_base_1_1_d_b_c.html">DBC</a></div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;  {</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    </div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="class_p_c_m_1_1_users_1_1_user_manager.html#a58c304ed2a3ae739b1d31a9eeace43e4">   36</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_p_c_m_1_1_users_1_1_user_manager.html#a58c304ed2a3ae739b1d31a9eeace43e4">add</a>($user) : bool</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    { </div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;      <span class="keywordflow">if</span> (!empty($user) &amp;&amp; ($user instanceof <a class="code" href="class_p_c_m_1_1_users_1_1_user.html">User</a>)) {        </div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;      </div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;        $add_user_query = $this-&gt;<a class="code" href="class_p_c_m_1_1_data_base_1_1_d_b_c.html#ae51244ccee8b1932cc60c3869d426f66">dbc</a>()-&gt;prepare(<span class="stringliteral">&quot;INSERT INTO `users` (`email`, `password`, `account_type`, `expiration_date`) VALUES (:email, :passwd, :account_type, ADDDATE(:expiration_date, INTERVAL 30 DAY))&quot;</span>);</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;      </div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        $add_user_query-&gt;bindValue(<span class="stringliteral">&quot;:email&quot;</span>, $user-&gt;login());</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        $add_user_query-&gt;bindValue(<span class="stringliteral">&quot;:passwd&quot;</span>, $user-&gt;password());</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        $add_user_query-&gt;bindValue(<span class="stringliteral">&quot;:account_type&quot;</span>, $user-&gt;accountType());</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        $add_user_query-&gt;bindValue(<span class="stringliteral">&quot;:expiration_date&quot;</span>, $user-&gt;expirationDate());</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;      </div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        <span class="keywordflow">return</span> $add_user_query-&gt;execute();</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;      </div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;      } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;      }</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    }</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    </div><div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="class_p_c_m_1_1_users_1_1_user_manager.html#ae272f79e7d5f42769425c2071281f4fd">   65</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_p_c_m_1_1_users_1_1_user_manager.html#ae272f79e7d5f42769425c2071281f4fd">user</a>(<span class="keywordtype">string</span> $login, <span class="keywordtype">string</span> $password) : <a class="code" href="class_p_c_m_1_1_users_1_1_user.html">User</a></div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    {</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;      <span class="keywordflow">if</span> (!empty($login) &amp;&amp; !empty($password)) {</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        $user_data = $this-&gt;<a class="code" href="class_p_c_m_1_1_data_base_1_1_d_b_c.html#a9307862af9ee08f7f911c98ef756642d">query</a>(</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        <span class="stringliteral">&quot;SELECT `email`, `password`, `account_type`, `expiration_date` FROM `users` WHERE `email`=:login AND `password`=:password&quot;</span>,[</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;          <span class="stringliteral">&quot;:login&quot;</span> =&gt; $login,</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;          <span class="stringliteral">&quot;:password&quot;</span> =&gt; $password</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;        ])[0];</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;        </div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <span class="keywordflow">if</span> (!empty($user_data)) {          </div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;          <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_p_c_m_1_1_users_1_1_user.html">User</a>(</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;            $user_data[<span class="stringliteral">&#39;email&#39;</span>],</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;            $user_data[<span class="stringliteral">&#39;password&#39;</span>],</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;            (<span class="keywordtype">int</span>)$user_data[<span class="stringliteral">&#39;account_type&#39;</span>],</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;            $user_data[<span class="stringliteral">&#39;expiration_date&#39;</span>]</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;          );</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;        } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;          <span class="keywordflow">throw</span> new \Exception(<span class="stringliteral">&quot;No such user in DB&quot;</span>);</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        }</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;      } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;        <span class="keywordflow">throw</span> new \Exception(<span class="stringliteral">&quot;Incorrect login or password&quot;</span>);</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;      }</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    }</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    </div><div class="line"><a name="l00093"></a><span class="lineno"><a class="line" href="class_p_c_m_1_1_users_1_1_user_manager.html#acec425b9bfc09e479e3a97429c324322">   93</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_p_c_m_1_1_users_1_1_user_manager.html#acec425b9bfc09e479e3a97429c324322">images</a>(<span class="keywordtype">string</span> $login) : array</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    {</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;      <span class="keywordflow">if</span> (!empty($login)) {</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        </div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        <span class="keywordflow">return</span> $this-&gt;<a class="code" href="class_p_c_m_1_1_data_base_1_1_d_b_c.html#a9307862af9ee08f7f911c98ef756642d">query</a>(<span class="stringliteral">&quot;SELECT ui.id_user_image, ui.id_user, ui.image FROM `users` u   INNER JOIN `user_images` ui ON u.id_user=ui.id_user WHERE u.email=:login;&quot;</span>, [</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;          <span class="stringliteral">&quot;:login&quot;</span> =&gt; $login</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        ]);</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        </div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;      } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="keywordflow">throw</span> new \Exception(<span class="stringliteral">&quot;Login is empty&quot;</span>);</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;      }</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    }</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    </div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    </div><div class="line"><a name="l00113"></a><span class="lineno"><a class="line" href="class_p_c_m_1_1_users_1_1_user_manager.html#ade449fa1c01f1d6d80edc0ed4929f1eb">  113</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">remove</span>($user_email) : <span class="keywordtype">bool</span></div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    {</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;      <span class="keywordflow">if</span> (!empty($user_email)) {</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;        $remove_user_query = $this-&gt;<a class="code" href="class_p_c_m_1_1_data_base_1_1_d_b_c.html#ae51244ccee8b1932cc60c3869d426f66">dbc</a>()-&gt;prepare(<span class="stringliteral">&quot;DELETE FROM `users` WHERE `email`=:user_email&quot;</span>);</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;        <span class="keywordflow">return</span> $remove_user_query-&gt;execute([</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;          <span class="stringliteral">&quot;:user_email&quot;</span> =&gt; $user_email</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        ]);</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;      } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;      }</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    }</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    </div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;  }</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  </div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;?&gt;</div><div class="ttc" id="namespace_p_c_m_1_1_users_html"><div class="ttname"><a href="namespace_p_c_m_1_1_users.html">PCM\Users</a></div><div class="ttdef"><b>Definition:</b> <a href="um_8class_8php_source.html#l00003">um.class.php:3</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_users_1_1_user_manager_html_acec425b9bfc09e479e3a97429c324322"><div class="ttname"><a href="class_p_c_m_1_1_users_1_1_user_manager.html#acec425b9bfc09e479e3a97429c324322">PCM\Users\UserManager\images</a></div><div class="ttdeci">images(string $login)</div><div class="ttdef"><b>Definition:</b> <a href="um_8class_8php_source.html#l00093">um.class.php:93</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_users_1_1_user_manager_html_a58c304ed2a3ae739b1d31a9eeace43e4"><div class="ttname"><a href="class_p_c_m_1_1_users_1_1_user_manager.html#a58c304ed2a3ae739b1d31a9eeace43e4">PCM\Users\UserManager\add</a></div><div class="ttdeci">add($user)</div><div class="ttdoc">Добавление нового пользователя </div><div class="ttdef"><b>Definition:</b> <a href="um_8class_8php_source.html#l00036">um.class.php:36</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_data_base_1_1_d_b_c_html_ae51244ccee8b1932cc60c3869d426f66"><div class="ttname"><a href="class_p_c_m_1_1_data_base_1_1_d_b_c.html#ae51244ccee8b1932cc60c3869d426f66">PCM\DataBase\DBC\dbc</a></div><div class="ttdeci">dbc()</div><div class="ttdoc">Возвращает контроллер базы данных </div><div class="ttdef"><b>Definition:</b> <a href="dbc_8class_8php_source.html#l00056">dbc.class.php:56</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_data_base_1_1_d_b_c_html"><div class="ttname"><a href="class_p_c_m_1_1_data_base_1_1_d_b_c.html">PCM\DataBase\DBC</a></div><div class="ttdoc">Базовый класс для все остальных менеджеров </div><div class="ttdef"><b>Definition:</b> <a href="dbc_8class_8php_source.html#l00024">dbc.class.php:24</a></div></div>
<div class="ttc" id="namespace_p_c_m_1_1_data_base_1_1_d_b_c_html"><div class="ttname"><a href="namespace_p_c_m_1_1_data_base_1_1_d_b_c.html">DBC</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_data_base_1_1_d_b_c_html_a9307862af9ee08f7f911c98ef756642d"><div class="ttname"><a href="class_p_c_m_1_1_data_base_1_1_d_b_c.html#a9307862af9ee08f7f911c98ef756642d">PCM\DataBase\DBC\query</a></div><div class="ttdeci">query(string $sql, array $params=array())</div><div class="ttdoc">Выполняет запрос </div><div class="ttdef"><b>Definition:</b> <a href="dbc_8class_8php_source.html#l00068">dbc.class.php:68</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_users_1_1_user_html"><div class="ttname"><a href="class_p_c_m_1_1_users_1_1_user.html">PCM\Users\User</a></div><div class="ttdoc">Описывает собой сущность - Пользователь </div><div class="ttdef"><b>Definition:</b> <a href="user_8class_8php_source.html#l00014">user.class.php:14</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_users_1_1_user_manager_html"><div class="ttname"><a href="class_p_c_m_1_1_users_1_1_user_manager.html">PCM\Users\UserManager</a></div><div class="ttdoc">Менеджер для работы с пользователями </div><div class="ttdef"><b>Definition:</b> <a href="um_8class_8php_source.html#l00026">um.class.php:26</a></div></div>
<div class="ttc" id="class_p_c_m_1_1_users_1_1_user_manager_html_ae272f79e7d5f42769425c2071281f4fd"><div class="ttname"><a href="class_p_c_m_1_1_users_1_1_user_manager.html#ae272f79e7d5f42769425c2071281f4fd">PCM\Users\UserManager\user</a></div><div class="ttdeci">user(string $login, string $password)</div><div class="ttdoc">Возвращает пользователя по его логину и паролю </div><div class="ttdef"><b>Definition:</b> <a href="um_8class_8php_source.html#l00065">um.class.php:65</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Документация по PHP Class Manager (Smart PHP). Последние изменения: Пн 28 Авг 2017 18:43:46. Создано системой &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
